package com.woniuxy.oa.dao;


import com.woniuxy.oa.dao.provider.EmployeeProvider;
import com.woniuxy.oa.entity.Employee;
import com.woniuxy.oa.entity.query.EmployeeQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * The interface Employee dao.
 *
 * @author 毓
 */
public interface EmployeeDAO {
    /**
     * Gets user list by user query.
     * 根据条件查询员工信息
     *
     * @param user the user
     * @return the user list by user query
     */
    @SelectProvider(type = EmployeeProvider.class, method = "select")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "deptName", property = "deptName"),
            @Result(column = "deptid", property = "dept.id")
    })
    List<Employee> getUserListByUserQuery(EmployeeQuery user);

    /**
     * Add employee.
     * 增加员工
     *
     * @param employee the employee
     * @return the employee
     */
    @Insert("insert into oa_emp values (#{id},#{empNo},#{name},#{password},#{phoneNum},#{birthDate},#{email},#{dept.id},#{gender}," +
            "#{avatar},#{level},#{entryTime},#{lastTime},#{lastIp},#{departureTime},#{status})")
    void add(Employee employee);

    /**
     * Update employee.
     * 更新员工信息
     *
     * @param employee the employee
     * @return the employee
     */
    @Update("update oa_emp set phoneNum=#{phoneNum},email=#{email},deptId=#{dept.id},gender=#{gender}, level=#{level},departureTime=#{departureTime},entryTime=#{entryTime},status=#{status},birthdate=#{birthDate} where id=#{id}")
    void update(Employee employee);

    /**
     * Del.锁定员工
     *
     * @param id the id
     */
    @Delete("update oa_emp set status='2' where id=#{id}")
    void del(String id);

    /**
     * Lock.停用账号
     *
     * @param id the id
     */
    @Update("update oa_emp set status='2' where id=#{id}")
    void lock(String id);

    /**
     * Use.启用账号
     *
     * @param id the id
     */
    @Update("update oa_emp set status='1' where id=#{id}")
    void use(String id);

    /**
     * Gets by id.通过id查询员工
     *
     * @param id the id
     * @return the by id
     */
    @Select("select * from oa_emp e where id=#{id} ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "deptid", property = "dept.id")
    })
    Employee getById(String id);

}
